import { SUBMIT_STATUS_MAP, SUBMIT_STATUS_COLOR_MAP } from './const.js'
export function tableColumns() {
  const self = this
  // const _getOperateLinkDisabled = function(self, row = {}) {
  //   let type = row.type
  //   // 华润集团数字化转型行动计划实施方案任务表
  //   if (type == 3) {
  //     // 没有操作链接权限
  //     return !self.hasPermission('GROUP_VIEW_DATA_OPERATE')
  //   } else {
  //     // 其它情况直接返回无权限（因为其它表无权限是去除操作链接的，所以虽然逻辑矛盾，但是不用想页面交互逻辑）
  //     return false
  //   }
  // }
  // const _getCheckLinkDisabled = function(self, row = {}) {
  //   let type = row.type
  //   // 华润集团数字化转型行动计划实施方案任务表
  //   if (type == 3) {
  //     // 没有操作链接权限
  //     return !self.hasPermission('GROUP_VIEW_DATA_CHECK')
  //   } else {
  //     // 其它情况直接返回无权限（因为其它表无权限是去除操作链接的，所以虽然逻辑矛盾，但是不用想页面交互逻辑）
  //     return false
  //   }
  // }
  const _getCheckLinkPermisson = function(self, row = {}) {
    let type = row.type
    // 任务表
    if (type == 1) {
      return self.hasPermission('CHECK_LINK')
      // 覆盖度表
    } else if (type == 2) {
      return self.hasPermission('COVER_RATE_CHECK_LINK')
      // 华润集团数字化转型行动计划实施方案任务表
    } else if (type == 3) {
      return self.hasPermission('GROUP_VIEW_DATA_CHECK')
    } else if (type == 4) {
      return self.hasPermission('COVER_READ_20')
    } else {
      return self.hasPermission('CHECK_LINK') || self.hasPermission('COVER_RATE_CHECK_LINK')
    }
  }
  // 任务表操作链接
  const _getOperateLinkPermisson = function(self, row = {}) {
    let type = row.type
    //业务单元实施任务表
    if (type == 1) {
      return self.hasPermission('OPERATE_LINK')
      // 覆盖度表
    } else if (type == 2) {
      return self.hasPermission('COVER_RATE_OPERATE_LINK')
      // 华润集团数字化转型行动计划实施方案任务表
    } else if (type == 3) {
      return false && self.hasPermission('GROUP_VIEW_DATA_OPERATE')
    } else if (type == 4) {
      return self.hasPermission('COVER_WRITE_20')
    } else {
      return self.hasPermission('OPERATE_LINK') || self.hasPermission('COVER_RATE_OPERATE_LINK')
    }
  }
  const _getStatisticsLinkPermisson = function(self, row = {}) {
    let type = row.type
    // 任务表
    if (type == 1) {
      return self.hasPermission('STATISTICS_LINK')
      // 覆盖度表
    } else if (type == 2 || type == 4) {
      return self.hasPermission('COVER_RATE_STATISTICS_LINK')
      // 华润集团数字化转型行动计划实施方案任务表
    } else if (type == 3) {
      return false
    } else {
      return self.hasPermission('STATISTICS_LINK') || self.hasPermission('COVER_RATE_STATISTICS_LINK')
    }
  }
  let list = [
    {
      title: '报表名称', // 应用名称
      key: 'name'
      // sortable: "custom"
    },
    {
      title: '操作',
      align: 'left',
      fixed: 'right',
      width: 130,
      render: (h, params) => {
        return h('RowTools', {
          props: {
            data: [
              {
                type: 'text',
                text: '操作',
                // hidden: !_getOperateLinkPermisson(self, params.row),
                optType: !_getOperateLinkPermisson(self, params.row) ? 'ashing' : '',
                handle: () => {
                  if (params.row.id == 2) {
                    // 关键业务环节数字化覆盖度
                    this.codeTest()
                  } else if (params.row.id == 1 || params.row.id == 3 || params.row.id == 4) {
                    this.checkFun(params.row)
                  }
                }
              },
              {
                type: 'text',
                text: '查看',
                // hidden: !_getCheckLinkPermisson(self, params.row),
                optType: !_getCheckLinkPermisson(self, params.row) ? 'ashing' : '',
                handle: () => {
                  if (params.row.id == 2) {
                    // 关键业务环节数字化覆盖度
                    this.codeTest()
                  } else if (params.row.id == 1 || params.row.id == 3 || params.row.id == 4) {
                    this.managementFun(params.row)
                  }
                }
              },
              {
                type: 'text',
                text: '统计',
                hidden: !_getStatisticsLinkPermisson(self, params.row),
                handle: () => {
                  if (params.row.id == 2) {
                    this.coverStatistics()
                  } else if (params.row.id == 1 || params.row.id == 4) {
                    this.statisticsFun(params.row)
                  }
                }
              }
            ]
          }
        })
      }
    }
  ]
  if (!_getCheckLinkPermisson(this) && !_getOperateLinkPermisson(this) && !_getStatisticsLinkPermisson(this)) {
    // 数据管理页进入 删除复选框
    list.forEach((e, i) => {
      if (e.title == '操作') {
        list.splice(i, 1)
      }
    })
  }

  return list
}

// '数字化转型专项实施方案任务表'
export function managemantColumns() {
  const _getSubmitStatus = function(row) {
    return SUBMIT_STATUS_MAP[row.submit]
  }
  return [
    {
      title: '业务单元', // 应用名称
      key: 'trgNode'
      // sortable: "custom"
    },

    {
      title: '提交情况', // 应用名称
      key: 'submit',
      render: (h, params) => {
        return h(
          'StatusButton',
          {
            props: {
              status: SUBMIT_STATUS_COLOR_MAP[params.row.submit]
            }
          },
          _getSubmitStatus(params.row)
        )
      }
    },

    {
      title: '操作',
      align: 'left',
      fixed: 'right',
      width: 250,
      render: (h, params) => {
        return h('RowTools', {
          props: {
            data: [
              {
                type: 'text',
                text: '查看报表',
                handle: () => {
                  this.viewReport(params.row)
                }
              },
              {
                type: 'text',
                text: '导出汇总',
                handle: () => {
                  this.downLoadFun(params.row)
                }
              },
              {
                type: 'text',
                text: '数据管理',
                handle: () => {
                  this.dataManagement(params.row)
                }
              }
            ]
          }
        })
      }
    }
  ]
}
// '关键业务环节数字化覆盖度'
export function managemantColumns2() {
  const _getSubmitStatus = function(row) {
    return SUBMIT_STATUS_MAP[row.submit]
  }
  return [
    {
      title: '业务单元', // 应用名称
      key: 'trgNode'
      // sortable: "custom"
    },

    {
      title: '提交情况', // 应用名称
      key: 'submit',
      render: (h, params) => {
        return h(
          'StatusButton',
          {
            props: {
              status: SUBMIT_STATUS_COLOR_MAP[params.row.submit]
            }
          },
          _getSubmitStatus(params.row)
        )
      }
    },

    {
      title: '操作',
      align: 'left',
      fixed: 'right',
      width: 170,
      render: (h, params) => {
        return h('RowTools', {
          props: {
            data: [
              {
                type: 'text',
                text: '查看报表',
                handle: () => {
                  this.viewReport(params.row)
                }
              },
              {
                type: 'text',
                text: '导出汇总',
                handle: () => {
                  this.downLoadFun(params.row)
                }
              }
            ]
          }
        })
      }
    }
  ]
}

// '华润集团数字化转型行动计划实施方案任务表'
export function managemantColumns3() {
  return [
    {
      title: '报表名称', // 应用名称
      key: 'reportName'
    },
    {
      title: '操作',
      align: 'left',
      fixed: 'right',
      width: 170,
      render: (h, params) => {
        return h('RowTools', {
          props: {
            data: [
              {
                type: 'text',
                text: '查看',
                handle: () => {
                  this.viewReport(params.row)
                }
              }
            ]
          }
        })
      }
    }
  ]
}

export function planDataColumns() {
  const self = this
  const _getEditHidden = function(params, self) {
    return params.row.wfStatus == 3 || self.fromPage == 'Summary'
  }
  const _getMidtermEditHidden = function(params, self) {
    // 中期修改标识 0-不可以 1-可以
    return params.row.midUpdateFlag == 0 || self.fromPage == 'Summary' || !self.hasPermission('MID-TERM-MODIFY')
  }
  const _getDeleteHidden = function(params, self) {
    return !(self.fromPage == 'Summary' && self.hasPermission('OFFICIAL-TASK-DELETE'))
  }
  const _getUpdateProgressHidden = function(params, self) {
    // updateFlag 更新进度标识 0-不可以更新 1-可以更新
    return params.row.updateFlag == 0 || self.fromPage == 'Summary'
  }
  const _getUpdateProgressDisabled = function(params, self) {
    if (self.writePermission === false) {
      return true
    } else {
      return false
    }
  }
  let list = [
    {
      type: 'selection',
      width: 45,
      align: 'center'
    },
    {
      title: '举措大类',
      key: 'stype'
    },
    {
      title: '举措细类',
      key: 'mtype'
    },
    {
      title: '重点任务',
      key: 'highTask',
      width: '250px'
    },
    {
      title: '更新时间',
      key: 'updateTime'
    },
    {
      title: '状态',
      key: 'wfStatusName',
      render: (h, params) => {
        return h('div', [
          h(
            'p',
            {
              style: {
                display: 'inline-block',
                maxWidth: '80px',
                overflow: 'hidden',
                textOverflow: 'ellipsis',
                whiteSpace: 'nowrap',
                color: params.row.wfStatusName == '驳回' ? '#E23928' : ''
              }
            },
            params.row.wfStatusName
          ),
          h(
            'Tooltip',
            {
              props: {
                transfer: true,
                // trigger: "hover",
                placement: 'left-end',
                maxWidth: '1000',
                content:
                  '审批意见：' +
                  (params.row.approverComments == null || params.row.approverComments == ''
                    ? '--'
                    : params.row.approverComments)
                // ontent: '审批意见：' + params.row.approverComments
              },
              style: {
                // float: "right",
                // backgroundColor: 'red'
              }
            },
            [
              h('Icon', {
                props: {
                  // type: (params.row.wfStatusName == '审核通过' || params.row.wfStatusName == '驳回') ? 'ios-book-outline' : ''
                  type:
                    !['审核通过', '驳回'].includes(params.row.wfStatusName) ||
                    params.row.approverComments == null ||
                    params.row.approverComments == ''
                      ? ''
                      : 'ios-book-outline'
                },
                style: {
                  fontSize: '18px',
                  position: 'relative',
                  top: '-5px',
                  left: '5px',
                  color: params.row.wfStatusName == '驳回' ? '#E23928' : ''
                }
              })
            ]
          )
        ])
      }
    },
    {
      title: '当前状态',
      key: 'currentStatus',
      render: (h, params) => {
        return h(
          'span',
          params.row.progressPercentage === null ||
            params.row.progressPercentage === '' ||
            params.row.progressPercentage === undefined
            ? '--'
            : params.row.currentStatus
            ? params.row.currentStatus
            : '--'
        )
      }
    },
    {
      title: '操作',
      align: 'left',
      fixed: 'right',
      width: 280,
      render: (h, params) => {
        return h('RowTools', {
          props: {
            data: [
              {
                type: 'text',
                text: '详情',
                handle: () => {
                  this.goDetail(params.row)
                }
              },
              {
                type: 'text',
                optType: _getUpdateProgressDisabled(params, self) ? 'ashing' : '',
                text: '更新进度',
                hidden: _getUpdateProgressHidden(params, self),
                handle: () => {
                  if (this.writePermission === false) {
                    return
                  }
                  this.goUpdateProgress(params.row)
                }
              },
              {
                type: 'text',
                text: '编辑',
                hidden: _getEditHidden(params, self),
                handle: () => {
                  this.goEdit(params.row)
                }
              },
              {
                type: 'text',
                text: '修订记录',
                handle: () => {
                  this.revisionRecord(params.row)
                }
              },
              {
                type: 'text',
                text: '中期修改',
                hidden: _getMidtermEditHidden(params, self),
                handle: () => {
                  this.midtermEdit(params.row)
                }
              },
              // {
              //   type: "text",
              //   text: '导出',
              //   hidden: !params.row.wfStatus || params.row.wfStatus == 2,
              //   handle: () => {
              //     this.exportFun(params.row);
              //   }
              // },
              {
                type: 'text',
                text: '删除',
                hidden: _getDeleteHidden(params, self),
                handle: () => {
                  this.deleteFun(params.row)
                }
              }
            ]
          }
        })
      }
    }
  ]
  if (this.fromPage !== 'creater') {
    // 数据管理页进入 删除复选框
    list.forEach((e, i) => {
      if (e.type == 'selection') {
        list.splice(i, 1)
      }
    })
    // 删除状态
    list.forEach((e, i) => {
      if (e.key == 'wfStatusName') {
        list.splice(i, 1)
      }
    })
  }
  return list
}

export function groupPlanDataColumns() {
  let self = this
  const _getEditHidden = function(params) {
    let statusList = ['-2', '-1', '0', '1'] //草稿,初始化中”、“初始化完成”、“填写中”可以编辑
    return statusList.includes(params.row.wfStatus) && self.hasPermission('GROUP_IMPLEMENT_ADMIN')
  }

  const _getRejectHidden = function(params) {
    let statusList = ['2', '3'] //提交、已通过可以驳回
    return statusList.includes(params.row.wfStatus) && self.hasPermission('GROUP_IMPLEMENT_ADMIN')
  }

  const _getUpdateHidden = function(params) {
    //具有填写权限的角色
    let statusList = ['1', '4'] //填写中、驳回可以更新进度
    return self.hasPermission('GROUP_IMPLEMENT_WRITE') && statusList.includes(params.row.wfStatus)
  }

  let list = [
    {
      type: 'selection',
      width: 45,
      align: 'center'
    },
    {
      title: '大类',
      key: 'stype'
    },
    {
      title: '小类',
      key: 'mtype'
    },
    {
      title: '重点任务',
      key: 'highTask'
    },
    {
      title: '重要程度',
      key: 'importance'
    },
    {
      title: '落实举措',
      key: 'taskMode'
    },
    {
      title: '预期成果',
      key: 'taskPreRs'
    },
    {
      title: '指标名称',
      key: 'indexName'
    },
    {
      title: '指标说明和计算方法',
      key: 'indexCalculationMethod'
    },
    {
      title: '预期指标',
      key: 'expectedIndicator'
    },
    {
      title: '责任部门',
      key: 'dpart'
    },
    {
      title: '是否完成',
      key: 'isFinished'
    },
    {
      title: '取得成果',
      key: 'actualAchievement'
    },
    {
      title: '成果关键指标2024年底标准值',
      key: 'keyIndex'
    },
    {
      title: '备注',
      key: 'todo'
    },
    {
      title: '状态',
      key: 'wfStatusName',
      render: (h, params) => {
        return h('div', [
          h(
            'p',
            {
              style: {
                display: 'inline-block',
                maxWidth: '80px',
                overflow: 'hidden',
                textOverflow: 'ellipsis',
                whiteSpace: 'nowrap',
                color: params.row.wfStatusName == '驳回' ? '#E23928' : ''
              }
            },
            params.row.wfStatusName
          ),
          h(
            'Tooltip',
            {
              props: {
                transfer: true,
                // trigger: "hover",
                placement: 'left-end',
                maxWidth: '1000',
                content:
                  '审批意见：' +
                  (params.row.approverComments == null || params.row.approverComments == ''
                    ? '--'
                    : params.row.approverComments)
                // ontent: '审批意见：' + params.row.approverComments
              },
              style: {
                // float: "right",
                // backgroundColor: 'red'
              }
            },
            [
              h('Icon', {
                props: {
                  // type: (params.row.wfStatusName == '审核通过' || params.row.wfStatusName == '驳回') ? 'ios-book-outline' : ''
                  type:
                    !['审核通过', '驳回'].includes(params.row.wfStatusName) ||
                    params.row.approverComments == null ||
                    params.row.approverComments == ''
                      ? ''
                      : 'ios-book-outline'
                },
                style: {
                  fontSize: '18px',
                  position: 'relative',
                  top: '-5px',
                  left: '5px',
                  color: params.row.wfStatusName == '驳回' ? '#E23928' : ''
                }
              })
            ]
          )
        ])
      }
    },
    {
      title: '操作',
      align: 'left',
      fixed: 'right',
      width: 280,
      render: (h, params) => {
        return h('RowTools', {
          props: {
            data: [
              // {
              //   type: "text",
              //   optType: _getUpdateProgressDisabled(params, self) ? 'ashing': '',
              //   text: '更新进度',
              //   hidden: _getUpdateProgressHidden(params, self),
              //   handle: () => {
              //     if (this.writePermission === false) {
              //       return
              //     }
              //     this.goUpdateProgress(params.row);
              //   }
              // },
              {
                type: 'text',
                text: '任务更新',
                hidden: !_getUpdateHidden(params),
                handle: () => {
                  this.goUpdate(params.row)
                }
              },
              {
                type: 'text',
                text: '编辑',
                hidden: !_getEditHidden(params),
                handle: () => {
                  this.goEdit(params.row)
                }
              },

              {
                type: 'text',
                text: '驳回',
                hidden: !_getRejectHidden(params, self),
                handle: () => {
                  this.goReject(params.row)
                }
              },
              {
                type: 'text',
                text: '查看', //详情
                handle: () => {
                  this.goDetail(params.row)
                }
              },
              {
                type: 'text',
                text: '流程记录', //修订记录
                handle: () => {
                  this.revisionRecord(params.row)
                }
              }
              // {
              //   type: "text",
              //   text: '中期修改',
              //   hidden: _getMidtermEditHidden(params, self),
              //   handle: () => {
              //     this.midtermEdit(params.row);
              //   }
              // },
            ]
          }
        })
      }
    }
  ]
  if (this.fromPage !== 'creater') {
    // 数据管理页进入 删除复选框
    // list.forEach((e, i) => {
    //   if(e.type == 'selection') {
    //     list.splice(i,1)
    //   }
    // })
    // 删除状态
    // list.forEach((e, i) => {
    //   if(e.key == 'wfStatusName') {
    //     list.splice(i,1)
    //   }
    // })
  }
  return list
}

export const columnList = [
  // { columnName: '编码', columnKey: 'taskCode' },
  { columnName: '举措大类', columnKey: 'stype', disabled: true },
  { columnName: '举措细类', columnKey: 'mtype', disabled: true },
  {
    columnName: '关键任务',
    columnKey: 'taskdesc',
    render: (h, params) => {
      return h(
        'span',
        params.row.taskdesc === null || params.row.taskdesc === '' || params.row.taskdesc === undefined
          ? '--'
          : params.row.taskdesc
      )
    }
  },
  // { columnName: '重点任务序号', columnKey: 'highTaskNo' },
  { columnName: '重点任务', columnKey: 'highTask', minWidth: 250 },
  { columnName: '落实举措', columnKey: 'taskMod' },
  { columnName: '预期业务价值', columnKey: 'taskPreRs' },
  {
    columnName: '计划开始时间',
    columnKey: 'startDate',
    minWidth: 160,
    render: (h, params) => {
      return h('span', params.row.startDate ? params.row.startDate.slice(0, 7) : '')
    }
  },
  {
    columnName: '计划完成时间',
    columnKey: 'endDate',
    minWidth: 160,
    render: (h, params) => {
      return h('span', params.row.endDate ? params.row.endDate.slice(0, 7) : '')
    }
  },
  { columnName: '责任部门', columnKey: 'dpart' },
  { columnName: '进度百分比(%)', columnKey: 'progressPercentage' },
  // {
  //   columnName: '进度百分比(%)', columnKey: 'progressPercentage', render: (h, params) => {
  //     return h('span', params.row.progressPercentage ? params.row.progressPercentage : '0')
  //   }
  // },
  // { columnName: '当前状态', columnKey: 'currentStatus' },
  { columnName: '季度', columnKey: 'taskQuarter' },
  {
    columnName: '当前状态',
    columnKey: 'currentStatus',
    render: (h, params) => {
      return h(
        'span',
        params.row.progressPercentage === null ||
          params.row.progressPercentage === '' ||
          params.row.progressPercentage === undefined
          ? '--'
          : params.row.currentStatus
          ? params.row.currentStatus
          : '--'
      )
    }
  },
  { columnName: '进度说明（每季度更新）', columnKey: 'statusNotice', minWidth: 170 },
  { columnName: '备注', columnKey: 'todo' },
  { columnName: '更新时间', columnKey: 'updateTime', minWidth: 160 },
  { columnName: '创建时间', columnKey: 'createTime', minWidth: 160 },
  {
    columnName: '状态',
    columnKey: 'wfStatusName',
    render: (h, params) => {
      return h('div', [
        h(
          'p',
          {
            style: {
              display: 'inline-block',
              maxWidth: '80px',
              overflow: 'hidden',
              textOverflow: 'ellipsis',
              whiteSpace: 'nowrap',
              color: params.row.wfStatusName == '驳回' ? '#E23928' : ''
            }
          },
          params.row.wfStatusName
        ),
        h(
          'Tooltip',
          {
            props: {
              transfer: true,
              // trigger: "hover",
              placement: 'left-end',
              maxWidth: '1000',
              content:
                '审批意见：' +
                (params.row.approverComments == null || params.row.approverComments == ''
                  ? '--'
                  : params.row.approverComments)
              // ontent: '审批意见：' + params.row.approverComments
            },
            style: {
              // float: "right",
              // backgroundColor: 'red'
            }
          },
          [
            h('Icon', {
              props: {
                // params.row.oldDataFlag：'1' 上线前的数据，'0' 上线后的数据，上线前的数据保持现有实现不变；对于上线后的数据，任务表列表上仅展示审批状态，不展示审批意见
                type:
                  !['审核通过', '驳回'].includes(params.row.wfStatusName) ||
                  params.row.approverComments == null ||
                  params.row.approverComments == '' ||
                  params.row.oldDataFlag == '0'
                    ? ''
                    : 'ios-book-outline'
              },
              style: {
                fontSize: '18px',
                position: 'relative',
                top: '-5px',
                left: '5px',
                color: params.row.wfStatusName == '驳回' ? '#E23928' : ''
              }
            })
          ]
        )
      ])
    }
  },
  { columnName: '业务单元', columnKey: 'trgNode' }
]

export const groupColumnList = [
  { columnName: '大类', columnKey: 'stype', disabled: true },
  { columnName: '小类', columnKey: 'mtype', disabled: true },
  { columnName: '重点任务', columnKey: 'highTask', disabled: true },
  { columnName: '重要程度', columnKey: 'importance' },
  { columnName: '落实举措', columnKey: 'taskMode' },
  { columnName: '预期成果', columnKey: 'taskPreRs' },
  { columnName: '指标名称', columnKey: 'indexName' },
  { columnName: '指标说明和计算方法', columnKey: 'indexCalculationMethod' },
  { columnName: '预期指标', columnKey: 'expectedIndicator' },
  { columnName: '责任部门', columnKey: 'dpart' },
  { columnName: '是否完成', columnKey: 'isFinished' },
  { columnName: '取得成果', columnKey: 'actualAchievement' },
  { columnName: '成果关键指标2023年底标准值', columnKey: 'keyIndex' },
  { columnName: '备注', columnKey: 'todo' },
  {
    columnName: '状态',
    columnKey: 'wfStatusName',
    render: (h, params) => {
      return h('div', [
        h(
          'p',
          {
            style: {
              display: 'inline-block',
              maxWidth: '80px',
              overflow: 'hidden',
              textOverflow: 'ellipsis',
              whiteSpace: 'nowrap',
              color: params.row.wfStatusName == '驳回' ? '#E23928' : ''
            }
          },
          params.row.wfStatusName
        ),
        h(
          'Tooltip',
          {
            props: {
              transfer: true,
              placement: 'left-end',
              maxWidth: '1000',
              content:
                '审批意见：' +
                (params.row.approverComments == null || params.row.approverComments == ''
                  ? '--'
                  : params.row.approverComments)
            }
          },
          [
            h('Icon', {
              props: {
                // params.row.oldDataFlag：'1' 上线前的数据，'0' 上线后的数据，上线前的数据保持现有实现不变；对于上线后的数据，任务表列表上仅展示审批状态，不展示审批意见
                type:
                  !['审核通过', '驳回'].includes(params.row.wfStatusName) ||
                  params.row.approverComments == null ||
                  params.row.approverComments == '' ||
                  params.row.oldDataFlag == '0'
                    ? ''
                    : 'ios-book-outline'
              },
              style: {
                fontSize: '18px',
                position: 'relative',
                top: '-5px',
                left: '5px',
                color: params.row.wfStatusName == '驳回' ? '#E23928' : ''
              }
            })
          ]
        )
      ])
    }
  }
]
